package bdd;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *Cette classe créé les tables de la base de données SQLite
 * @author Shaance
 */
public class CreationTables {

    public Connection c = null;
    public Statement stmt = null;

    public void create() throws SQLException {

        c=ConnecterBase.Connect();
        creerTableScores();
        creerTablePhrases();
        //creerTableMots();
        creerTableOptions();
        c.close();
    }

    public void creerTableScores() throws SQLException {

        stmt = c.createStatement();
        String sql = "CREATE TABLE SCORES"
                + "(ID_SCORE INTEGER PRIMARY KEY AUTOINCREMENT,"
                + " NOM_JOUEUR           TEXT    NOT NULL, "
                + " SCORE            INTEGER     NOT NULL, "
                + " TEMPS            INTEGER     NOT NULL)";
        try {
            stmt.executeUpdate(sql);
        } catch (SQLException s) {
        }
        stmt.close();
    }

    public void creerTablePhrases() throws SQLException {

        stmt = c.createStatement();
        String sql = "CREATE TABLE PHRASES"
                + "(ID_PHRASE INTEGER PRIMARY KEY AUTOINCREMENT,"
                + " PHRASE           TEXT    NOT NULL, "
                + " VALEUR            BOOLEAN     NOT NULL)";
        try {
            stmt.executeUpdate(sql);
        } catch (SQLException s) {
        }
        stmt.close();

    }

    public void creerTableMots() throws SQLException {

        stmt = c.createStatement();
        String sql = "CREATE TABLE MOTS"
                + "(ID_MOT INTEGER PRIMARY KEY AUTOINCREMENT,"
                + " MOT           TEXT    NOT NULL, "
                + " VALEUR            BOOLEAN     NOT NULL)";
        try {
            stmt.executeUpdate(sql);
        } catch (SQLException s) {
        }
        stmt.close();

    }
    
    public void creerTableOptions() throws SQLException {

        stmt = c.createStatement();
        String sql = "CREATE TABLE OPTIONS"
                + " (JEU           INTEGER PRIMARY KEY,"
                + " OPTION            TEXT     NOT NULL,"
                 + " VALEUR           INTEGER    NOT NULL ); ";
        try {
            stmt.executeUpdate(sql);
            stmt.executeUpdate("INSERT OR IGNORE INTO OPTIONS VALUES (1,'TEMPS',30)");
        } catch (SQLException s) {
        }
        stmt.close();

    }

}
